﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using HYRevitCode.FormUtility;

namespace YArchitech.Plumbing
{
	public partial class FormMultiPipeDraw : HYBaseForm
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		public FormMultiPipeDraw(Document doc)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			List<KeyValuePair<System.Windows.Forms.Control, bool>> inputControlGroup = new List<KeyValuePair<System.Windows.Forms.Control, bool>>();
			this.m_thisManger = new ControlInfoManager(this, inputControlGroup, "{F2BFB034-BDA9-423B-BC35-ABB8B3F66B4E}", null);
			this.doc = doc;
			base.Icon = Resource.YArchitechIcon;
			this.SetDrawViewFlag();
		}

		private void SetDrawViewFlag()
		{
			if (this.doc.ActiveView.Name.Contains("空调水管"))
			{
				this.drawView = DrawView.AirConditioningWaterPipe;
				return;
			}
			if (this.doc.ActiveView.Name.Contains("采暖"))
			{
				this.drawView = DrawView.HeatingPipe;
				return;
			}
			this.drawView = DrawView.GPSPipe;
		}

		private void btnAlongWallDraw_Click(object sender, EventArgs e)
		{
			if (this.BindDataToAllDrawPipes())
			{
				FormAlongWallDraw formAlongWallDraw = new FormAlongWallDraw();
				formAlongWallDraw.txtBoxAloWallDis.Text = this.dataGridViewPipe.Rows[0].Cells[4].Value.ToString();
				if (formAlongWallDraw.ShowDialog(this) == DialogResult.OK)
				{
					this.OperationType = DrawingType.DrawFollowingWall;
					this.cancelOperationType = CancelMessageType.CancelByProgramme;
					this.SwithStatus();
					this.cancelOperationType = CancelMessageType.CancelByProgramme;
					this.awdt = formAlongWallDraw.PipeDisType;
					this.disToWall = formAlongWallDraw.DisToWall;
					return;
				}
			}
			else
			{
				YJKMessageBox.Show("存在绘制管道参数漏项，请检查！");
			}
		}

		private void btnPipeDeriDraw_Click(object sender, EventArgs e)
		{
			if (this.BindDataToAllDrawPipes())
			{
				FormPipeDeriDraw formPipeDeriDraw = new FormPipeDeriDraw();
				if (formPipeDeriDraw.ShowDialog(this) == DialogResult.OK)
				{
					this.OperationType = DrawingType.DrawFromExistingPipe;
					this.cancelOperationType = CancelMessageType.CancelByProgramme;
					this.SwithStatus();
					this.cancelOperationType = CancelMessageType.CancelByProgramme;
					this.dpos = formPipeDeriDraw.PipeOffSet;
					this.pipeOffDis = formPipeDeriDraw.PipeOff;
					this.pipeLevel = formPipeDeriDraw.PipeLevel;
					return;
				}
			}
			else
			{
				YJKMessageBox.Show("存在绘制管道参数漏项，请检查！");
			}
		}

		private void btnDelet_Click(object sender, EventArgs e)
		{
			try
			{
				List<DataGridViewRow> list = new List<DataGridViewRow>();
				foreach (object obj in this.dataGridViewPipe.SelectedCells)
				{
					DataGridViewRow owningRow = ((DataGridViewCell)obj).OwningRow;
					if (!list.Contains(owningRow))
					{
						list.Add(owningRow);
					}
				}
				this.dataGridViewPipe.ClearSelection();
				if (list.Count > 0)
				{
					if (this.dataGridViewPipe.RowCount > 1)
					{
						using (List<DataGridViewRow>.Enumerator enumerator2 = list.GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								DataGridViewRow dataGridViewRow = enumerator2.Current;
								if (dataGridViewRow.Cells[0].Value.ToString().Trim() != "" || dataGridViewRow.Cells[1].Value.ToString().Trim() != "" || dataGridViewRow.Cells[2].Value.ToString().Trim() != "" || dataGridViewRow.Cells[3].Value.ToString().Trim() != "" || dataGridViewRow.Cells[4].Value.ToString().Trim() != "")
								{
									this.dataGridViewPipe.Rows.Remove(dataGridViewRow);
								}
							}
							goto IL_19F;
						}
					}
					this.dataGridViewPipe.Rows.Clear();
				}
				IL_19F:
				this.cmbPipeInfo.Visible = false;
				this.BindDataToAllDrawPipes();
				this.dataGridViewPipe.Update();
			}
			catch (Exception ex)
			{
				YJKMessageBox.Warning(ex.Message);
			}
		}

		private void FormMultiPipeDraw_Load(object sender, EventArgs e)
		{
			if (this.m_thisManger != null && !this.m_thisManger.SetControlInfoToForm())
			{
				base.Location = new System.Drawing.Point(230, 170);
			}
			this.GetPipeSysAndTypeName();
			this.LoadPipeData();
			this.cmbPipeInfo.Visible = false;
			this.cmbPipeInfo.SelectedIndexChanged += this.cmbPipeInfo_SelectedIndexChanged;
			this.cmbPipeInfo.TextChanged += this.cmbPipeInfo_TextChanged;
			this.dataGridViewPipe.Controls.Add(this.cmbPipeInfo);
			this.DataGridViewNotSortable(this.dataGridViewPipe);
			this.dataGridViewPipe.ClearSelection();
			for (int i = 0; i < this.dataGridViewPipe.Columns.Count; i++)
			{
				DataGridViewColumn dataGridViewColumn = this.dataGridViewPipe.Columns[i];
				if (i == 2)
				{
					dataGridViewColumn.Width = 60;
				}
				else if (i == 3 || i == 4)
				{
					dataGridViewColumn.Width = 85;
				}
				else
				{
					dataGridViewColumn.Width = 100;
				}
			}
			base.KeyPreview = true;
		}

		private void dataGridViewPipe_Scroll(object sender, ScrollEventArgs e)
		{
			this.cmbPipeInfo.Visible = false;
		}

		private void dataGridViewPipe_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
		{
			this.cmbPipeInfo.Visible = false;
		}

		private void dataGridViewPipe_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			if (this.dataGridViewPipe.RowCount > 3 && e.RowIndex < this.dataGridViewPipe.RowCount - 2)
			{
				this.drData = this.dtData.NewRow();
				if (e.RowIndex != -1)
				{
					this.drData[0] = this.dataGridViewPipe.Rows[e.RowIndex].Cells[0].Value.ToString();
					this.drData[1] = this.dataGridViewPipe.Rows[e.RowIndex].Cells[1].Value.ToString();
					this.drData[2] = this.dataGridViewPipe.Rows[e.RowIndex].Cells[2].Value.ToString();
					this.drData[3] = this.dataGridViewPipe.Rows[e.RowIndex].Cells[3].Value.ToString();
					this.drData[4] = this.dataGridViewPipe.Rows[e.RowIndex].Cells[4].Value.ToString();
				}
			}
			if (this.dataGridViewPipe.CurrentCell.ColumnIndex == 0 || this.dataGridViewPipe.CurrentCell.ColumnIndex == 1 || this.dataGridViewPipe.CurrentCell.ColumnIndex == 2)
			{
				this.dataGridViewPipe.CurrentCell.ReadOnly = true;
			}
			try
			{
				string text = this.dataGridViewPipe.CurrentCell.Value.ToString();
				string pipeTypeName = this.dataGridViewPipe.Rows[this.dataGridViewPipe.CurrentCell.RowIndex].Cells[1].Value.ToString();
				if ((this.dataGridViewPipe.CurrentCell.ColumnIndex == 0 || this.dataGridViewPipe.CurrentCell.ColumnIndex == 1 || this.dataGridViewPipe.CurrentCell.ColumnIndex == 2) && this.dataGridViewPipe.CurrentCell.RowIndex != this.dataGridViewPipe.RowCount - 1)
				{
					switch (this.dataGridViewPipe.CurrentCell.ColumnIndex)
					{
					case 0:
						this.BindingComboBoxInfo(this.listPipingSystemType, false);
						break;
					case 1:
						this.BindingComboBoxInfo(this.listPipeType, false);
						break;
					case 2:
						this.listPipeDis.Clear();
						foreach (MEPSize mepsize in this.GetPipeSegmentByPipeTypeName(pipeTypeName).GetSizes())
						{
							this.listPipeDis.Add(Math.Round(304.8 * mepsize.NominalDiameter, MidpointRounding.AwayFromZero).ToString());
						}
						this.BindingComboBoxInfo(this.listPipeDis, false);
						break;
					}
					Rectangle cellDisplayRectangle = this.dataGridViewPipe.GetCellDisplayRectangle(this.dataGridViewPipe.CurrentCell.ColumnIndex, this.dataGridViewPipe.CurrentCell.RowIndex, true);
					this.cmbPipeInfo.Text = text;
					this.cmbPipeInfo.Left = cellDisplayRectangle.Left;
					this.cmbPipeInfo.Top = cellDisplayRectangle.Top;
					this.cmbPipeInfo.Width = cellDisplayRectangle.Width;
					this.cmbPipeInfo.Height = cellDisplayRectangle.Height;
					this.cmbPipeInfo.Visible = true;
					this.dataGridViewPipe.CurrentCell.Value = this.cmbPipeInfo.Text;
				}
				else
				{
					this.cmbPipeInfo.Visible = false;
				}
			}
			catch
			{
			}
		}

		private void dataGridViewPipe_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
		{
			this.cellValue = this.dataGridViewPipe.CurrentCell.Value.ToString();
			this.cell = this.dataGridViewPipe.CurrentCell;
		}

		private void dataGridViewPipe_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.RowIndex == this.dataGridViewPipe.RowCount - 1)
			{
				this.btnDelet.Enabled = false;
				return;
			}
			this.btnDelet.Enabled = true;
		}

		private void dataGridViewPipe_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			if (this.dataGridViewPipe.RowCount > 1)
			{
				if (e.ColumnIndex == 3 && e.RowIndex < this.dataGridViewPipe.RowCount - 1 && !this.regex.IsMatch(this.dataGridViewPipe.CurrentCell.Value.ToString().Trim()))
				{
					this.dataGridViewPipe.CurrentCell.Value = this.cellValue;
					YJKMessageBox.Show("输入数字格式不正确,应为正负整数或小数，且不能为空！");
				}
				if (e.ColumnIndex == 4 && e.RowIndex < this.dataGridViewPipe.RowCount - 1 && !this.regex.IsMatch(this.dataGridViewPipe.CurrentCell.Value.ToString().Trim()))
				{
					this.dataGridViewPipe.CurrentCell.Value = this.cellValue;
					YJKMessageBox.Show("输入数字格式不正确,应为正负整数或小数，且不能为空！");
				}
			}
			this.dataGridViewPipe.Update();
			this.BindDataToAllDrawPipes();
		}

		private void dataGridViewPipe_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			if (this.dataGridViewPipe.RowCount > 1)
			{
				if (e.RowIndex == this.dataGridViewPipe.Rows.Count - 1)
				{
					if (this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[0].Value.ToString().Trim() != "" && this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[1].Value.ToString().Trim() != "" && this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[2].Value.ToString().Trim() != "" && this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[3].Value.ToString().Trim() != "" && this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[4].Value.ToString().Trim() != "")
					{
						this.dtData = (this.dataGridViewPipe.DataSource as DataTable);
						if (this.dtData != null)
						{
							DataTable dataTable = this.dtData.Copy();
							this.dataGridViewPipe.DataSource = dataTable;
							this.dtData.Rows.RemoveAt(dataTable.Rows.Count - 1);
							int columnIndex = e.ColumnIndex;
							if (this.drData == null)
							{
								this.drData = this.dtData.NewRow();
								this.drData[0] = this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[0].Value.ToString();
								this.drData[1] = this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[1].Value.ToString();
								this.drData[2] = this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[2].Value.ToString();
								this.drData[3] = this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[3].Value.ToString();
								this.drData[4] = this.dataGridViewPipe.Rows[e.RowIndex - 1].Cells[4].Value.ToString();
							}
							this.dtData.Rows.Add(this.drData);
							DataRow row = this.dtData.NewRow();
							this.dtData.Rows.Add(row);
							this.dataGridViewPipe.DataSource = this.dtData;
							this.dataGridViewPipe.CurrentCell = this.dataGridViewPipe[columnIndex, this.dataGridViewPipe.Rows.Count - 2];
							this.drData = null;
						}
					}
					else
					{
						YJKMessageBox.Warning("当前管道信息参数未输入完整前不允许新添加管道！");
					}
				}
			}
			else
			{
				DataRow row2 = this.dtData.NewRow();
				this.dtData.Rows.Add(row2);
				this.dataGridViewPipe.DataSource = this.dtData;
			}
			if (this.dataGridViewPipe.CurrentCell.ColumnIndex == 0 || this.dataGridViewPipe.CurrentCell.ColumnIndex == 1 || this.dataGridViewPipe.CurrentCell.ColumnIndex == 2)
			{
				this.dataGridViewPipe.CurrentCell.ReadOnly = true;
			}
		}

		public List<DrawPipeStruct> AllDrawPipes
		{
			get
			{
				return this.allDrawPipes;
			}
		}

		private void LoadPipeData()
		{
			ClassMultiPipeXMLInfo.InitializeFilePath(FormMultiPipeDraw.path, "MultiPipeDraw");
			this.readDrawPipes = ClassMultiPipeXMLInfo.RaedInfoFromXML(FormMultiPipeDraw.path, this.drawView.ToString());
			if (this.readDrawPipes.Count > 0)
			{
				for (int i = 0; i < this.readDrawPipes.Count; i++)
				{
					if (!this.listPipingSystemType.Contains(this.readDrawPipes[i].pipingSysName))
					{
						this.readDrawPipes.RemoveAt(i);
					}
				}
			}
			this.dtData.Columns.Add("系统名称");
			this.dtData.Columns.Add("管道类型");
			this.dtData.Columns.Add("管径(mm)");
			this.dtData.Columns.Add("管道标高(mm)");
			this.dtData.Columns.Add("邻管间距(mm)");
			DataRow dataRow;
			if (this.readDrawPipes.Count == 0)
			{
				if (this.listPipingSystemType.Count > 0 && this.listPipeType.Count > 0)
				{
					this.listPipeDis.Clear();
					foreach (MEPSize mepsize in this.GetPipeSegmentByPipeTypeName(this.listPipeType.ElementAt(0)).GetSizes())
					{
						this.listPipeDis.Add(Math.Round(304.8 * mepsize.NominalDiameter, MidpointRounding.AwayFromZero).ToString());
					}
					if (this.drawView == DrawView.HeatingPipe)
					{
						if (this.listPipingSystemType.Contains("采暖供水系统"))
						{
							dataRow = this.dtData.NewRow();
							dataRow[0] = this.listPipingSystemType.FirstOrDefault((string p) => p == "采暖供水系统");
							dataRow[1] = this.listPipeType.ElementAt(0);
							dataRow[2] = this.listPipeDis.ElementAt(0);
							dataRow[3] = "2750";
							dataRow[4] = "200";
							this.dtData.Rows.Add(dataRow);
						}
						if (this.listPipingSystemType.Contains("采暖回水系统"))
						{
							dataRow = this.dtData.NewRow();
							dataRow[0] = this.listPipingSystemType.FirstOrDefault((string p) => p == "采暖回水系统");
							dataRow[1] = this.listPipeType.ElementAt(0);
							dataRow[2] = this.listPipeDis.ElementAt(0);
							dataRow[3] = "2750";
							dataRow[4] = "200";
							this.dtData.Rows.Add(dataRow);
						}
					}
					else if (this.drawView == DrawView.AirConditioningWaterPipe)
					{
						if (this.listPipingSystemType.Contains("冷水供水系统"))
						{
							dataRow = this.dtData.NewRow();
							dataRow[0] = this.listPipingSystemType.FirstOrDefault((string p) => p == "冷水供水系统");
							dataRow[1] = this.listPipeType.ElementAt(0);
							dataRow[2] = this.listPipeDis.ElementAt(0);
							dataRow[3] = "2750";
							dataRow[4] = "200";
							this.dtData.Rows.Add(dataRow);
						}
						if (this.listPipingSystemType.Contains("冷水回水系统"))
						{
							dataRow = this.dtData.NewRow();
							dataRow[0] = this.listPipingSystemType.FirstOrDefault((string p) => p == "冷水回水系统");
							dataRow[1] = this.listPipeType.ElementAt(0);
							dataRow[2] = this.listPipeDis.ElementAt(0);
							dataRow[3] = "2750";
							dataRow[4] = "200";
							this.dtData.Rows.Add(dataRow);
						}
						if (this.listPipingSystemType.Contains("冷凝水系统"))
						{
							dataRow = this.dtData.NewRow();
							dataRow[0] = this.listPipingSystemType.FirstOrDefault((string p) => p == "冷凝水系统");
							dataRow[1] = this.listPipeType.ElementAt(0);
							dataRow[2] = this.listPipeDis.ElementAt(0);
							dataRow[3] = "2750";
							dataRow[4] = "200";
							this.dtData.Rows.Add(dataRow);
						}
					}
					else if (this.drawView == DrawView.GPSPipe)
					{
						if (this.listPipingSystemType.Count < 3)
						{
							using (List<string>.Enumerator enumerator2 = this.listPipingSystemType.GetEnumerator())
							{
								while (enumerator2.MoveNext())
								{
									string value = enumerator2.Current;
									dataRow = this.dtData.NewRow();
									dataRow[0] = value;
									dataRow[1] = this.listPipeType.ElementAt(0);
									dataRow[2] = this.listPipeDis.ElementAt(0);
									dataRow[3] = "2750";
									dataRow[4] = "200";
									this.dtData.Rows.Add(dataRow);
								}
								goto IL_6C0;
							}
						}
						for (int j = 0; j < 3; j++)
						{
							dataRow = this.dtData.NewRow();
							dataRow[0] = this.listPipingSystemType.ElementAt(j);
							dataRow[1] = this.listPipeType.ElementAt(0);
							dataRow[2] = this.listPipeDis.ElementAt(0);
							dataRow[3] = "2750";
							dataRow[4] = "200";
							this.dtData.Rows.Add(dataRow);
						}
					}
				}
				else
				{
					YJKMessageBox.Show("当前项目中系统类型或管道类型为空");
				}
			}
			else if (this.readDrawPipes.Count > 0)
			{
				foreach (ReadPipeStruct readPipeStruct in this.readDrawPipes)
				{
					dataRow = this.dtData.NewRow();
					dataRow[0] = readPipeStruct.pipingSysName;
					dataRow[1] = readPipeStruct.pipeTypeName;
					dataRow[2] = readPipeStruct.pipeDiameter;
					dataRow[3] = readPipeStruct.levelOffSet;
					dataRow[4] = readPipeStruct.offSet;
					this.dtData.Rows.Add(dataRow);
				}
			}
			IL_6C0:
			dataRow = this.dtData.NewRow();
			this.dtData.Rows.Add(dataRow);
			this.dataGridViewPipe.DataSource = this.dtData;
		}

		private void BindingComboBoxInfo(List<string> ItemContants, bool bEdit = false)
		{
			if (this.cmbPipeInfo == null)
			{
				this.cmbPipeInfo = new ComboBox();
			}
			DataTable dataTable = new DataTable();
			dataTable.Columns.Add("Value");
			dataTable.Columns.Add("Contants");
			for (int i = 0; i < ItemContants.Count; i++)
			{
				DataRow dataRow = dataTable.NewRow();
				dataRow[0] = i;
				dataRow[1] = ItemContants[i];
				dataTable.Rows.Add(dataRow);
			}
			this.cmbPipeInfo.ValueMember = "Value";
			this.cmbPipeInfo.DisplayMember = "Contants";
			this.cmbPipeInfo.DataSource = dataTable;
			if (bEdit)
			{
				this.cmbPipeInfo.DropDownStyle = ComboBoxStyle.DropDown;
				return;
			}
			this.cmbPipeInfo.DropDownStyle = ComboBoxStyle.DropDownList;
		}

		private void cmbPipeInfo_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.dataGridViewPipe.CurrentCell.Value = ((ComboBox)sender).Text;
		}

		private void cmbPipeInfo_TextChanged(object sender, EventArgs e)
		{
			this.dataGridViewPipe.CurrentCell.Value = ((ComboBox)sender).Text;
		}

		public PipeSegment GetPipeSegmentByPipeTypeName(string pipeTypeName)
		{
			RoutingPreferenceManager routingPreferenceManager = this.GetPipeTypeByTypeName(pipeTypeName).RoutingPreferenceManager;
			return this.doc.GetElement(routingPreferenceManager.GetRule((Autodesk.Revit.DB.RoutingPreferenceRuleGroupType)0, 0).MEPPartId) as PipeSegment;
		}

		public PipeType GetPipeTypeByTypeName(string typeName)
		{
			IList<Element> list = new FilteredElementCollector(this.doc).OfClass(typeof(PipeType)).ToElements();
			if (list.Count > 0)
			{
				foreach (Element element in list)
				{
					if (typeName == element.Name)
					{
						return element as PipeType;
					}
				}
				return list[0] as PipeType;
			}
			return null;
		}

		public PipingSystemType GetPipeSysTypeName(string sysTypeName)
		{
			IList<Element> list = new FilteredElementCollector(this.doc).OfClass(typeof(PipingSystemType)).ToElements();
			if (list.Count > 0)
			{
				foreach (Element element in list)
				{
					if (sysTypeName == element.Name)
					{
						return element as PipingSystemType;
					}
				}
				return list[0] as PipingSystemType;
			}
			return null;
		}

		private string GetCloserNum(string sNum, List<double> snewNums)
		{
			if (snewNums.Count == 0)
			{
				return null;
			}
			int num = (int)short.Parse(sNum);
			double num2 = snewNums[0];
			double num3 = Math.Abs((double)num - num2);
			for (int i = 0; i < snewNums.Count; i++)
			{
				if (Math.Abs((double)num - snewNums[i]) <= num3)
				{
					num3 = Math.Abs((double)num - snewNums[i]);
					if (num2 < snewNums[i])
					{
						num2 = snewNums[i];
					}
				}
			}
			return num2.ToString();
		}

		private bool BindDataToAllDrawPipes()
		{
			bool result = true;
			this.allDrawPipes.Clear();
			if (this.dataGridViewPipe.RowCount == 1)
			{
				result = false;
				ClassMultiPipeXMLInfo.WritePipeStruct(FormMultiPipeDraw.path, this.drawView.ToString(), this.allDrawPipes);
			}
			else
			{
				this.allDrawPipes = this.GetDrawPipes();
				if (this.allDrawPipes.Count == 0)
				{
					result = false;
				}
				ClassMultiPipeXMLInfo.WritePipeStruct(FormMultiPipeDraw.path, this.drawView.ToString(), this.allDrawPipes);
			}
			return result;
		}

		public List<DrawPipeStruct> GetDrawPipes()
		{
			List<DrawPipeStruct> list = new List<DrawPipeStruct>();
			int num = 0;
			while (num < this.dataGridViewPipe.RowCount - 1 && !(this.dataGridViewPipe.Rows[num].Cells[0].Value.ToString().Trim() == "") && !(this.dataGridViewPipe.Rows[num].Cells[1].Value.ToString().Trim() == "") && !(this.dataGridViewPipe.Rows[num].Cells[2].Value.ToString().Trim() == "") && !(this.dataGridViewPipe.Rows[num].Cells[3].Value.ToString().Trim() == "") && !(this.dataGridViewPipe.Rows[num].Cells[4].Value.ToString().Trim() == ""))
			{
				list.Add(new DrawPipeStruct
				{
					pipingSystem = this.GetPipeSysTypeName(this.dataGridViewPipe.Rows[num].Cells[0].Value.ToString()),
					pipeType = this.GetPipeTypeByTypeName(this.dataGridViewPipe.Rows[num].Cells[1].Value.ToString()),
					pipeDiameter = double.Parse(this.dataGridViewPipe.Rows[num].Cells[2].Value.ToString()),
					levelOffSet = double.Parse(this.dataGridViewPipe.Rows[num].Cells[3].Value.ToString()),
					offSet = double.Parse(this.dataGridViewPipe.Rows[num].Cells[4].Value.ToString())
				});
				num++;
			}
			return list;
		}

		private void GetPipeSysAndTypeName()
		{
			foreach (Element element in new FilteredElementCollector(this.doc).OfClass(typeof(PipeType)).ToElements())
			{
				this.listPipeType.Add(element.Name);
			}
			foreach (Element element2 in new FilteredElementCollector(this.doc).OfClass(typeof(PipingSystemType)).ToElements())
			{
				this.listPipingSystemType.Add(element2.Name);
			}
		}

		private void DataGridViewNotSortable(DataGridView dgv)
		{
			for (int i = 0; i < dgv.Columns.Count; i++)
			{
				dgv.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
			}
		}

		protected void SwithStatus()
		{
			Cursor.Position = new System.Drawing.Point(Cursor.Position.X + 20, Cursor.Position.Y);
			this.SetFocusToMainWnd();
			this.PressESCKey();
		}

		protected void SetFocusToMainWnd()
		{
			int wMsg = 7;
			FormMultiPipeDraw.SendMessage(DrawMultiPipeCommand.hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
		}

		protected void PressESCKey()
		{
			int bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			int wMsg = 7;
			FormMultiPipeDraw.SendMessage(DrawMultiPipeCommand.hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			FormMultiPipeDraw.keybd_event((byte)bVk, 0, dwFlags, 0);
			FormMultiPipeDraw.keybd_event((byte)bVk, 0, dwFlags2, 0);
		}

		private void FormMultiPipeDraw_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.cancelOperationType = CancelMessageType.EndCancel;
			this.BindDataToAllDrawPipes();
			this.PressESCKey();
		}

		private void FormMultiPipeDraw_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\u001b')
			{
				base.Close();
			}
		}

		private void dataGridViewPipe_MouseLeave(object sender, EventArgs e)
		{
			this.dataGridViewPipe.EndEdit();
		}

		private void FormMultiPipeDraw_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (this.m_thisManger != null)
			{
				this.m_thisManger.GetControlInfoToXml();
			}
		}

		private List<string> listPipingSystemType = new List<string>();

		private List<string> listPipeType = new List<string>();

		private List<string> listPipeDis = new List<string>();

		private List<DrawPipeStruct> allDrawPipes = new List<DrawPipeStruct>();

		private List<ReadPipeStruct> readDrawPipes = new List<ReadPipeStruct>();

		public static string path = Path.Combine(Product.DataLocation, "HYDrawParallelPipeInfo.xml");

		private DataTable dtData = new DataTable();

		private Document doc;

		private ComboBox cmbPipeInfo = new ComboBox();

		private DataRow drData;

		private DrawView drawView;

		public double disToWall;

		public AlongWallDisType awdt;

		public double? pipeOffDis;

		public DeriPipeOffSet dpos;

		public double pipeLevel;

		public DrawingType OperationType;

		private ControlInfoManager m_thisManger;

		public CancelMessageType cancelOperationType = CancelMessageType.undifined;

		private string cellValue;

		private DataGridViewCell cell;

		private Regex regex = new Regex("^[+-]?[0-9]+\\d*[.]?\\d*$");
	}
}
